#include <iostream>

using namespace std;

const int N = 1e6 + 10;

int n;
int a[N];
int f[N], len;

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];

	//f[i]表示最长子序列长度为i时的最小元素
	for(int i = 1; i <= n; i++)
	{
		//处理边界情况
		if(len == 0 || a[i] > f[len]) f[++len] = a[i];
		else 
		{
			//二分插入位置
			int l = 1, r = len;
			while(l < r)
			{
				int mid = (l + r) / 2;
				if(f[mid] < a[i]) l = mid + 1;
				else r = mid;
			}
			f[l] = a[i];
		}
	}
	cout << len << endl;

	return 0;
}